{% extends "admin/admin_layout.html" %}
{% block admin_title %}管理操作{% endblock %}
{% block admin_head %}
{% endblock %}
{% set perm = request.perm_const %}
{% block admin_content %}
<div class="sect">
	<h2>操作列表
    	<span class="sub">共{{ page.paginator.count }}个操作</span>
        <span class="extra">
        	{% if perm.check_perm_op(perm.perm_op,perm.op_add) %}
        	<a href="javascript:;" class="act_add" onclick="add_op(event);">添加操作</a>
        	{% endif %}
        </span>
    </h2>
    <div class="sectContent">
    	<table id="op_table" class="gTable">
        	<tr>
            	<th class="m1"></th>
                <th class="m4">ID</th>
                <th class="m0">操作名</th>
            	<th class="m1"></th>
                <th class="m4">ID</th>
                <th class="m0">操作名</th>
            	<th class="m1"></th>
                <th class="m4">ID</th>
                <th class="m0">操作名</th>
            </tr>
            <tr>
            {% for obj in page.object_list %}
            	<td class="m1">
                	<input type="checkbox" autocomplete="off" value="{{ obj.id }}"  id="chk_{{ obj.id }}" />
                </td>
                <td class="m4">{{ obj.id }}</td>
                <td>{% if perm.check_perm_op(perm.perm_op,perm.op_add) %}
                	<a href="javascript:;" onclick="edit_op(event,'{{ obj.id }}','{{ obj.name }}');">{{ obj.name }}</a>
                	{% else %}{{obj.name}}{% endif %}
                </td>
                {% if loop.index % 3 == 0 %}</tr><tr>{% endif %}
            {% endfor %}
            </tr>
            <tr>
            	<td><input type="checkbox" autocomplete="off" id="chkAll" onclick="$checkAll('op_table','chkAll');" /></td>
                <td colspan="8">
                	{% if perm.check_perm_op(perm.perm_op,perm.op_del) %}
                	<input type="button" class="button btns" value="删除选中" onclick="del_op('op_table','chkAll');" />
                	{% endif %}
                </td>
            </tr>
        </table>
        {% include "paginator.html" %}
    </div>
</div>
{% endblock %}
{% block popup_content %}
    <div id="s_op_div" class="popup" style="display:none;">
    	<div class="sect">
        	<h2>
            	<span id="s_op_title" class="title"></span>
                <span class="extra" onclick="$('s_op_div').tHide();">关闭</span>
            </h2>
            <div class="sectContent gForm">
            	<div id="id_row" class="row">
                	<label>操作ID：</label>
                    <input type="text" class="inputbox" id="op_id" />
                    <input type="hidden" id="op_former_id" />
                </div>
            	<div id="name_row" class="row">
                	<label>操作名：</label>
                    <input type="text" class="inputbox" id="op_name" />
                </div>
                <div class="sectBtn">
                	<input type="button" class="button" value="确定" onclick="do_op();" />
                    <a href="javascript:;" onclick="$('s_op_div').tHide();">取消</a>
                </div>
            </div>
        </div>
    </div>
<script type="text/javascript">
function add_op(ev){
    $("s_op_title").innerHTML = "添加操作";$("op_former_id").value = "";$("op_id").value = "";$("op_name").value = "";
    $('s_op_div').fshow({event:ev});
}
function edit_op(ev, id, name){
    $("s_op_title").innerHTML = "修改操作";$("op_former_id").value = id;$("op_id").value = id;$("op_name").value = name;
    $('s_op_div').fshow({event:ev});
}
function do_op(){
    var to_url = "";var former_id = $("op_former_id").value;var id = $("op_id").value;
	var name = $("op_name").value;var params = "";
    if (id == null || id == undefined || id == "") {new MsgBox({message:"你还未输入操作ID"});return;}
    if (name == null || name == undefined || name == "") {new MsgBox({message:"你还未输入操作名"});return;}
    params = String.format("id={0}&name={1}&former_id={2}", id, String.encode(name), former_id);
    new echoAjax({url:"/admin/op/do/", params:params,reLoad:true}).fire();
}
function del_op(parent, chkall){
    if (!confirm("你确定要删除选中的内容吗？"))return;
    var ids = $getCheckValues(parent, chkall);
    if (!ids) {new MsgBox({message:"没有选中任何内容"});return;}
    var params = "value=" + ids;
    new echoAjax({url:"/admin/op/delete/", params:params,reLoad:true}).fire();
}
</script>
{% endblock %}
